// app.js
const storage = require('./utils/storage.js');

App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 初始化全局音频管理器
    this.globalData.audioManager = wx.getBackgroundAudioManager();
    
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log('登录成功', res.code);
      }
    })
    
    // 获取用户信息
    const userInfo = storage.getUserInfo();
    if (userInfo) {
      this.globalData.userInfo = userInfo;
    }
  },
  
  globalData: {
    userInfo: null,
    audioManager: null,
    currentMusic: null,
    playlist: [],
    playIndex: 0
  }
})
